/**
 * @description list的路由控制器
 * @author 盘古他爹
 */

import { listDoNotExist, addListError, delListError } from "../config/errorInfo"
import ResponseModel from "../config/response.config"
import ListService from "../service/list/pandaKill.service"
import { ILikeListOne } from "../model/listModel/listPandaKill"
import { C, N } from "../types"

enum listNames {
    // listOne = "LikeListOne",
    // listTwo = "LikeListTwo"
    like_list_one,
    LikeListTwo
}

class ListController {

    //通用list查询
    async getList(ctx: any)  {
        console.log("参数", ctx.request.query);
        // ctx.body = "获取列表"
        // return
            //请求参数在列表名单中
            const list = await ListService.getListContent({...ctx.query})
            console.log("res", list);
            
            if(list) {
                ctx.body = ResponseModel.success({list},  "获取列表成功")
                 return
            }
            
        
         ctx.body = ResponseModel.error(listDoNotExist)
        
        
        
        
    }

    //通用list添加
    async addList(ctx:C) {
        const info = ctx.request.body
        let listData = info.listData
        listData.forEach((item: any) => {
            item.label =  item.label.toString()
        })
        try {
            const res = await ListService.addListContentOne(info.listData)
        ctx.body = ResponseModel.success({msg:"添加成功"})
        } catch (err) {
            console.error(err)
            ctx.body = ResponseModel.error(addListError)
        }
        
        
    }

    //通用list删除
    async delList(ctx: C) {
        let { deleteList } = ctx.request.body
        deleteList.forEach((item: any) => {
            item.status = 0
        });
        console.log("deleteList", typeof deleteList[0].id);
        const res = await ListService.delListContentOne(deleteList)
        if(!res) {
            ctx.body = ResponseModel.error(delListError)
            return
        }
        ctx.body = ResponseModel.success({msg: "删除成功!", data: {}})
        
    }

}

export default new ListController()